<?PHP

 define('DMDIRC', true);
 require_once('/home/dmdirc/www/blog/wp-config.php');

 function getNews($num = 5) {

  $sql = "
    SELECT 
      post_title, post_content, post_date_gmt, guid
    FROM
      wp_terms
      NATURAL JOIN wp_term_taxonomy
      NATURAL JOIN wp_term_relationships
      INNER JOIN wp_posts ON(ID = object_id)
    WHERE
      name = 'News'
    ORDER BY post_date DESC
    LIMIT 0,$num";

  mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
  mysql_select_db(DB_NAME);

  $res = mysql_query($sql);
  $ret = array();

  while ($row = mysql_fetch_assoc($res)) {
   $ret[] = array(
    'title' => $row['post_title'],
    'body' => $row['post_content'],
    'date' => strtotime($row['post_date_gmt']),
    'link' => $row['guid']
   );
  }

  return $ret;
 }
  

?>
